import request from '@/utils/request'

export function getLuckTree(type, is_next) {
  /*
  * 获取本期奖池列表
  * type	numeric	奖池类型,非必传
  * is_next	numeric	是否下期奖池1是0否,默认0,非必传
  * */
  return request({
    url:"/lucky/tree",
    method: 'get',
    params: {
      type, is_next
    }
  })
}

export function delLuckGift(id, is_next = true) {
  /*
  * 删除某个礼物
  * */
  return request({
    url: '/lucky/tree',
    method: 'delete',
    params: {id, is_next}
  })
}

export function toAlterOrAddGift({type, is_next, id, number, gift_id}) {
  /*
  * 修改或新增奖池
  * */
  return request({
    url: '/lucky/tree',
    method: 'post',
    data: {
      type,id, number, gift_id, is_next
    }
  })
}

export function getSpecialData() {
  /*
  * 获取特殊奖池列表
  * */
  return request({
    url: '/lucky/tree/special',
    method: 'get',
    params: {
      type: 30
    }
  })
}

export function getSpecialUserList(page) {
  /*
  * 获取特殊用户列表
  * prizePool : 奖池
  * size : 数量
  * */
  return request({
    url: '/personal/user',
    method: 'get',
    params: {page}
  })
}

export function alterOrAddPersonalUser({id, user_code, expired_time}) {
  return request({
    url: '/personal/user',
    method: 'post',
    data: {
      id, user_code, expired_time
    }
  })
}

export function delPersonalUser(id) {
  return request({
    url:'/personal/user',
    method: 'delete',
    params: {id}
  })
}


export function getPersonalPool(type) {
  /*
  * 获取特殊个人奖池配置
  *
  * */
  return request({
    url: '/personal/pool',
    method: 'get',
    params: {type}
  })

}

export function alterOrAddPersonalPool({type, id, number, gift_id}) {
  /*
  * 添加或者修改 特殊个人奖池
  * */
  return request({
    url: '/personal/pool',
    method: 'post',
    params: {type, id, number, gift_id}
  })
}


export function delPersonalPool(id) {
  return request({
    url: '/personal/pool',
    method: 'delete',
    params: {id}
  })
}

export function getLuckyTreeList() {
  return request({
    url: '/lucky/tree/special',
    method: 'get',
    params: {type: 30}
  })
}

export function toUpdateRatio({min_ratio, max_ratio, min_self_ratio, max_self_ratio}) {
  return request({
    url: '/lucky/tree/ratio',
    method: 'post',
    data: {min_ratio, max_ratio, min_self_ratio, max_self_ratio}
  })
}

export function getGiftList({sold, type, name, blind_box_type, page, perPage}) {
  /*
  * 获取礼物列表
  * */
  return request({
    url: '/gift/list',
    method: 'post',
    data: {sold, type, name, blind_box_type, perPage, page}
  })
}

export function toPersonalSetConfig({number, types}) {
  /*
  * 特殊个人奖池设置
  * types  ep： 1,3,4
  * */
  types = types.join(',')
  return request({
    url: '/personal/set',
    method: 'post',
    data: {number, types}
  })
}

export function toReplace(type) {
  /*
  * 替换新奖池
  *
  * */
  return request({
    url: '/lucky/tree/replace',
    method: 'post',
    data: {type}
  })
}

export function toModifyMultiple({type, is_next, gift_detail}) {
  /*
  * 一键修改
  * */
  return request({
    url: '/lucky/tree/all',
    method: 'post',
    data: {type, is_next, gift_detail}
  })
}


export function toModifyMultiplePerson({type, is_next, gift_detail}) {
  return request({
    url: '/personal/all',
    method: 'post',
    data: {type, is_next, gift_detail}
  })
}


/**
 * getRatio
 * @desc 获取暴击奖池比率
 * @param type_id 奖池类型(十连百连--1 特殊个人--40 个人独立--50 )
 * @param pool_type 类型id
 * @returns {AxiosPromise}
 */
export function getRatio(type_id, pool_type) {
  return request({
    url: '/critical/ratio',
    method: 'get',
    params: { pool_type, type_id }
  })
}


// 设置
export function setRatio({ ratio, pool_type, type_id }) {
  return request({
    url: '/critical/ratio',
    method: 'put',
    data: { ratio, pool_type, type_id }
  })
}


/**
 * setNumCritical
 * @desc 设置暴击数量
 * @param critical_times  暴击数量
 * @param pool_type  奖池类型(1公用奖池 40特殊个人 50个人独立)
 * @param pool_type_id 奖池id
 * @param gift_id 礼物id
 * @param user_id 用户id
 * @param is_next 是否本期奖池 1是 0否（私池改自己的传1 改公有默认池传0）
 * @returns {AxiosPromise}
 */
export function setNumCritical({ critical_times, pool_type, pool_type_id, gift_id, user_id, is_next }) {
  return request({
    url: '/critical/num/set',
    method: 'post',
    data: { critical_times, pool_type, pool_type_id, gift_id, user_id, is_next }
  })
}


/**
 * getUserPool
 * @desc 特殊个人奖池查看用户详情
 * @param user_id 用户id
 * @returns {AxiosPromise}
 */
export function getUserPool(user_id) {
  return request({
    url: 'personal/user/pool',
    method: 'get',
    params: { user_id }
  })
}

/**
 * getPoolUserMeg
 * @desc 暴击奖池详情(个人奖池)
 * @param user_id 用户id
 * @param pool_type 奖池类型(40特殊个人 50个人独立)
 * @returns {AxiosPromise}
 */
export function getPoolUserMeg(user_id, pool_type) {
  return request({
    url: '/critical/pool/prize',
    method: 'get',
    params: { user_id, pool_type }
  })
}


